//
//  BaseViewController.swift
//  CMCCIOTSwift
//
//  Created by isoftstone on 2017/4/17.
//  Copyright © 2017年 isoftstone. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
     var masView : CommonDragMsgView? = nil
    override func viewDidLoad() {
        super.viewDidLoad()
         self.navBarLeftTitle(title: "<")
        

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
   
    //MARK:- NavigationBar
    func navBarLeftImage(image : String) {
        let barButtonItem = UIBarButtonItem(image: UIImage(named:image), style: .plain, target: self, action: #selector(navBarLeftAction(sender:)))
        self.navigationItem.leftBarButtonItem = barButtonItem
    }
    func navBarRightImage(image : String) {
        let barButtonItem = UIBarButtonItem(image : UIImage(named:image),style: .plain,target: self,action:#selector(navBarRightAction(sender:)))
        self.navigationItem.rightBarButtonItem = barButtonItem
    }
    func navBarLeftTitle(title : String) {
        let barBtnItem  =  UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(navBarLeftAction(sender:)))
        self.navigationItem.leftBarButtonItem = barBtnItem
        
    }
    func navBarLeftAction(sender : UIBarButtonItem){
        
        if let navController =  self.navigationController {
            navController.popViewController(animated: true)
        }
        
    }
    func navBarRightAction(sender : UIBarButtonItem) {
        
    }
    
    
    //MARK:- ShowMessage
    func startLoading(_ content : String) {
        self.dismiss()
        self.stopLoading()
        masView = CommonDragMsgView(frame: self.view.frame)
        masView?.initUI(type: .Loading)
        masView?.setMessage(title: content)
        self.view.addSubview(masView!)
    }
    func showInfo(_ content : String) {
        self .stopLoading()
        self .dismiss()
        masView = CommonDragMsgView(frame: self.view.frame)
        masView?.initUI(type: .Info)
        masView?.setMessage(title: content)
        self.view.addSubview(masView!)
    }
    func showError(_ content : String) {
        self .stopLoading()
        self .dismiss()
        masView = CommonDragMsgView(frame: self.view.frame)
        masView?.initUI(type: .Info)
        masView?.setMessage(title: content)
        self.view.addSubview(masView!)
    }
    func stopLoading(){
        
        masView?.stopLoading()
    }
    func dismiss() {
        
        masView?.disMissMessage()
    }
    
    
}
